package web.servlet.old;

import com.alibaba.fastjson.JSON;
import com.pzhu.pojo.Brand;
import com.pzhu.service.BrandService;
import com.pzhu.service.impl.BrandServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
//@WebServlet("/brandSelectAll")
public class BrandSelectAllServlet extends HttpServlet {
    BrandService brandService = new BrandServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查询所有数据
        List<Brand> brands = brandService.selectAll();
        //通过JSON.toJSONString把对象转换为字符串
        String s = JSON.toJSONString(brands);

        resp.setContentType("text/json;charset=utf-8");

        resp.getWriter().write(s);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
